package com.saber.accumulator;

import java.util.HashMap;
import java.util.Map;

import com.saber.bean.Report;
import com.saber.bean.ReportItem;


/**
 *
 * @author
 *
 */

public class AccumulateTypeConfig {

	public static final String DEFAULT_SUFFIX = ".default";

	/**
	 *
	 */
	private Map<String, ReportItem.AccumulatorType> typeMap;

	/**
	 *
	 */
	public AccumulateTypeConfig() {
		this.typeMap = new HashMap<String, ReportItem.AccumulatorType>();
		this.typeMap.put(Report.ReportName.KPI.name() + "." + Report.ReportItemName.request_total, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.KPI.name() + "." + Report.ReportItemName.error_total, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.KPI.name() + "." + Report.ReportItemName.in_tx_total, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.KPI.name() + "." + Report.ReportItemName.out_tx_total, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.HTTP_Request_Client_IP_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.HTTP_Response_Code_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_QPS_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Connection_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		//qxw_add_start
		this.typeMap.put(Report.ReportName.Service_Realtime_Connection_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Week_Connection_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Realtime_Traffic_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Week_Traffic_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Network_Current_OUT_TX_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Network_Current_OUT_TX_HTTP_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Current_QPS_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Current_QPS_Response_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		//qxw_add_end
		this.typeMap.put(Report.ReportName.SERVICE_CONNECTION_CITY_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Network_IN_TX_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.Service_Network_OUT_TX_Report.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.APP_SERVICE_NETWORK_TOPOLOGY_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.SERVICE_HOST_NETWORK_TOPOLOGY_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);

		this.typeMap.put(Report.ReportName.JVM_MEMORY_HEAP_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);
		this.typeMap.put(Report.ReportName.JVM_MEMORY_OTHER_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);
		this.typeMap.put(Report.ReportName.JVM_MMEORY_GC_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);

		this.typeMap.put(Report.ReportName.JVM_MEMORY_HEAP_MAX_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);
		this.typeMap.put(Report.ReportName.JVM_MEMORY_HEAP_USED_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);
		this.typeMap.put(Report.ReportName.JVM_MEMORY_HEAP_COMMITED_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);
		this.typeMap.put(Report.ReportName.JVM_MEMORY_YOUNG_GC_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);
		this.typeMap.put(Report.ReportName.JVM_MEMORY_FULL_GC_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);

		this.typeMap.put(Report.ReportName.JVM_MEMORY_OTHER_PERMGEN_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);
		this.typeMap.put(Report.ReportName.JVM_MEMORY_OTHER_CODE_CACHE_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);

		this.typeMap.put(Report.ReportName.JVM_THREAD_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.NONE);

		this.typeMap.put(Report.ReportName.SERVICE_RESPONSE_TIME_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.AVG);

		this.typeMap.put(Report.ReportName.SERVICE_CONNECTION_CLIENT_IP_WINDOW_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.SERVICE_REQUEST_CLIENT_IP_WINDOW_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
		this.typeMap.put(Report.ReportName.SERVICE_TRAFFIC_CLIENT_IP_WINDOW_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);

		this.typeMap.put(Report.ReportName.SERVICE_CURRENT_CONNECTION_REPORT.name() + DEFAULT_SUFFIX, ReportItem.AccumulatorType.SUM);
	}

	/**
	 *
	 * @param reportName
	 * @param key
	 * @return
	 */
	public ReportItem.AccumulatorType getType(String reportName, String key) {
		ReportItem.AccumulatorType type = this.typeMap.get(reportName + "." + key);
		if(null == type) {
			type = this.typeMap.get(reportName + DEFAULT_SUFFIX);
		}
		return null == type ? ReportItem.AccumulatorType.NONE : type;
	}
}
